﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MbUnit.Framework;
using fit;
using System.IO;

namespace Frost.Tests.FitTestStrategySpecs {
    
    [TestFixture]
    public class when_running_my_mock_fit_test : with_fit_test_strategy  {
        protected IResult results;
        
        protected override void Because_of() {
            results = _fitTestStrategy.RunTest(_MockFitTest);
        }    
        
        [Test]
        public void should_not_return_exceptions() {
            _MockFitTest.Exceptions.ShouldBeEmpty();
        }

        [Test]
        public void should_return_fit_result() {
            results.ShouldBeTypeOf<FitResult>();
        }

        [Test]
        public void should_have_expected_output() {
            results.ToString().ShouldBe(@" 
            <table>
                <tr><td>Frost.Tests.FitTestStrategySpecs.MockFitTest</td></tr>
                <tr><td>WasCalled</td></tr>
                <tr><td>true</td></tr>
            </table>
            ");
        }

    }

    [TestFixture]
    public class when_running_a_test_that_isnt_a_fit_test : with_fit_test_strategy {
        protected override void Because_of() {
            
        }

        [Test]
        [ExpectedException(typeof(IncorrectTestTypeException))]
        public void should_throw_incorrect_test_type_exception() {
            _fitTestStrategy.RunTest(new NullTest());
        }
    }
    public abstract class with_fit_test_strategy {
        public FitTestStrategy _fitTestStrategy;
        public ITest _MockFitTest;

        [SetUp]
        public void Setup() {
            _fitTestStrategy = new FitTestStrategy();

            _MockFitTest = new FitTest();
            _MockFitTest.LoadTest(new StringReader(@" 
            <table>
                <tr><td>Frost.Tests.FitTestStrategySpecs.MockFitTest</td></tr>
                <tr><td>WasCalled</td></tr>
                <tr><td>true</td></tr>
            </table>
            "));

            Because_of();
                        
        }

        protected abstract void Because_of();

    }

    public class MockFitTest : ColumnFixture {
        public bool WasCalled { get; set; }
    }
}
